package com.gzz.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gzz.common.R;
import com.gzz.pojo.SystemMessage;
import com.gzz.pojo.UserAdvise;
import com.gzz.service.SystemMessageService;
import com.gzz.service.UserAdviseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import static cn.hutool.core.date.DateTime.now;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周佳成
 * @since 2023-12-09
 */
@RestController
@RequestMapping("/api/system-message")
public class SystemMessageController {
    @Autowired
    SystemMessageService systemMessageService;
    @Autowired
    UserAdviseService userAdviseService;
    private SystemMessage systemMessage;

    @PutMapping("/add")
    public R addMessage(@RequestBody SystemMessage systemMessage)
    {

        UpdateWrapper<UserAdvise> userAdviseUpdateWrapper = new UpdateWrapper<>();
        userAdviseUpdateWrapper.eq("id",systemMessage.getAdviceId());
        userAdviseUpdateWrapper.set("isRead",1);
        userAdviseService.update(userAdviseUpdateWrapper);
        this.systemMessage = systemMessage;
        systemMessage.setCreateTime(now());
        systemMessageService.save(systemMessage);
        return R.success(true);
    }

}

